package cn.study.luckyapp.assembler;

import cn.study.luckyclient.dto.ActivityAddCmd;
import cn.study.luckyclient.dto.ActivityUpdateCmd;
import cn.study.luckyclient.dto.data.ActivityVo;
import cn.study.luckydomain.activity.ActivityEntity;
import cn.study.luckydomain.activity.ActivityTime;

import java.time.LocalDateTime;

public class ActivityAssembler {
    public static ActivityEntity toAddEntity(ActivityAddCmd cmd) {
        ActivityEntity activityEntity = new ActivityEntity();
        activityEntity.setActivityName(cmd.getActivityName());
        activityEntity.setTime(new ActivityTime(cmd.getStartTime(),cmd.getEndTime()));
        activityEntity.setDescribe(cmd.getDescribe());
        activityEntity.setCreateTime(LocalDateTime.now());
        activityEntity.setCreator("小三");
        activityEntity.setUpdateTime(LocalDateTime.now());
        activityEntity.setUpdater("小三");

        return activityEntity;
    }

    public static ActivityVo toActivityVO(ActivityEntity entity) {
        ActivityVo activityVO = new ActivityVo();
        activityVO.setId(entity.getId());
        activityVO.setActivityName(entity.getActivityName());
        activityVO.setStartTime(entity.getTime().getStartTime());
        activityVO.setEndTime(entity.getTime().getEndTime());
        activityVO.setDescribe(entity.getDescribe());
        activityVO.setCreateTime(entity.getCreateTime());
        activityVO.setCreator(entity.getCreator());
        activityVO.setUpdateTime(entity.getUpdateTime());
        activityVO.setUpdater(entity.getUpdater());
        activityVO.setStatus(entity.getTime().getStatus().getValue());

        return activityVO;
    }

    public static ActivityEntity toUpdateEntity(ActivityUpdateCmd cmd) {
        ActivityEntity activityEntity = new ActivityEntity();
        activityEntity.setId(cmd.getId());
        activityEntity.setActivityName(cmd.getActivityName());
        activityEntity.setTime(new ActivityTime(cmd.getStartTime(), cmd.getEndTime()));
        activityEntity.setDescribe(cmd.getDescribe());
        activityEntity.setUpdateTime(LocalDateTime.now());
        activityEntity.setUpdater("小三");

        return activityEntity;
    }
}
